package com.yunyike.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yunyike.mapper.SupplierMapper;
import com.yunyike.model.Supplier;
import com.yunyike.service.SupplierService;

@Service("supplierServiceImpl")
public class SupplierServiceImpl implements SupplierService{

	private Logger log = LoggerFactory.getLogger(SupplierServiceImpl.class);

	@Autowired
	private SupplierMapper supplierMapper;

	public List<Supplier> findAllSuppliers() {
		return supplierMapper.findAllSuppliers();
	}

	/**
	 * 根据供应商id查询供应商信息（多个）
	 */
	public Map<String, Supplier> findSuppliersByIds(List<String> supplierIds) {
		
		List<Supplier> findSuppliersByIds = supplierMapper.findSuppliersByIds(supplierIds);
		if(findSuppliersByIds == null || findSuppliersByIds.isEmpty()){
			return null;
		}
		
		Map<String, Supplier> supplierMap = new HashMap<String, Supplier>();
		for (Supplier supplier : findSuppliersByIds) {
			String supplierIdDB = supplier.getSupplierId();
			
			for (String supplierId : supplierIds) {
				if(supplierIdDB.equals(supplierId)){
					supplierMap.put(supplierId, supplier);
					break;
				}
			}
		}
		
		return supplierMap;
		
	}
	
}
